package com.twotwoshop.service.goods.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.twotwoshop.domin.goods.pojo.ProductComment;
import com.twotwoshop.domin.goods.pojo.ProductFavorite;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
public interface ProductFavoriteMapper extends BaseMapper<ProductFavorite> {


    @Insert({
            "<script>",
            "INSERT INTO product_favorite (user_id, product_id, created_time) VALUES ",
            "<foreach collection='favorites' item='favorite' separator=','>",
            "(#{favorite.userId}, #{favorite.productId}, #{favorite.createdTime})",
            "</foreach>",
            "ON DUPLICATE KEY UPDATE ",
            "created_time = VALUES(created_time)",
            "</script>"
    })
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void insertBatvh(@Param("favorites") List<ProductFavorite> favorites);
}